package com.henau;

import com.henau.dao.ICarTeamMapper;
import com.henau.domain.CarTeam;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.Reader;
import java.util.List;

public class test2 {
    private Reader reader = null;
    private SqlSession sqlSession = null;
    private ICarTeamMapper mapper = null;

    @Before
    public void init() throws IOException {
        reader = Resources.getResourceAsReader("SqlMapConfig.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader);
        sqlSession = factory.openSession();
        mapper = sqlSession.getMapper(ICarTeamMapper.class);
    }

    @After
    public void destroy() throws IOException {
        sqlSession.commit();
        sqlSession.close();
        reader.close();
    }
    @Test
    public void findAll() throws Exception {
        List<CarTeam> all = mapper.findAll();
        for (CarTeam carTeam:all) {
            System.out.println(carTeam);
        }
    }
    @Test
    public void findCarTeamByNme() throws Exception{
        CarTeam name = mapper.findCarTeamByName("赵文豪车队");
        System.out.println(name);
    }
    @Test
    public void addCarTeam() throws Exception{
        CarTeam carteam = new CarTeam("刘鑫车队222","刘鑫","15000000000","刘鑫公司","刘鑫666");
        int i = mapper.addCarTeam(carteam);
        System.out.println(i);
    }
    @Test
    public void deletCarTeam() throws Exception{
        int i = mapper.deleteCarTeam("刘鑫车队111");
        System.out.println(i);
    }
    @Test
    public void updateCarTeam() throws Exception{
        CarTeam name = mapper.findCarTeamByName("刘鑫车队");
        name.setCarCompany("刘鑫123公司");
        int i = mapper.updateCarTeam(name);
        System.out.println(i);
    }
    @Test
    public void ydd() throws Exception{
        List<CarTeam> carTeams = mapper.yTOd();
        for (CarTeam carteam:carTeams) {
            System.out.println(carteam);
        }

    }
}